define(function () {
    return function (pane) {
        /**
         * 导航
         */
        {
            pane.html(utils.getHtml('default_table'));
        }

        //初始化工具
        utils.addTools(pane, [
            {className: 'refresh-btn', icon: 'fa-refresh', text: '刷新'}
        ]);
        $(pane).on('click', '.refresh-btn', function () {
            if (table) {
                table.api().draw();
            }
        });

        //初始化表格
        var table = utils.dataTable(pane, {
            columns_arrays: [
                ["id", "#"],
                ["agency_id", "代理", false, function (i, t, row) {
                    var user = row.agency;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>';
                }, 'filterable'],
                ["user_id", "用户", false, function (i, t, row) {
                    var user = row.user;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>';
                }, 'filterable'],
                ["keyword", "关键词", false, function (keyword) {
                    return '<div style="max-width: 200px;"><a target="_blank" href="http://pyl.kkdd789.com/?keyword=' + keyword + '">' + (keyword || '') + '</a></div>';
                }],
                ["goods_id", "商品", false, function (i, t, row) {
                    var goods = row.goods;
                    if (!goods) {
                        return '<div style="min-width: 300px;"></div>';
                    }
                    return '<div style="min-width: 300px;">' + (goods.pictUrl ? '<img src="' + goods.pictUrl + '?imageView2/1/w/150/h/150/q/75"> ' : '') + (goods.title) + '' +
                        '<div>原价:' + goods.zkPrice + ', 优惠券: ' + (goods.quanAmount || goods.couponAmount || '-') + ', 佣金:' + (goods.tkCommFee || '-') + '/' + (goods.eventFee || '') + '&nbsp;&nbsp;&nbsp;<a href="/detail?id=' + goods.auctionId + '" target="_blank">打开商品</a></div>' +
                        (row.goods_remove ? '<div>已删除</div>' : '') + '</div>';
                }, 'filterable'],
                ["created_at", "创建日期", false, utils.dateTimeRender()]
            ],
            sorting: [[0, 'desc']],
            fnServerData: function (paramData) {
                return adminApi('searchs_browse', paramData);
            }
        });
    }
});
